package top.healthylife.basics.utils.config.nacos;

import cn.hutool.core.io.FileUtil;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
import java.util.Optional;
import java.util.Properties;

/**
 * Nacos
 *
 * @author maoxiaomeng
 */
@Slf4j
@Configuration
public class NacosMetaDataConfiguration {

    @Bean
    public Void MetaData(NacosDiscoveryProperties nacosDiscoveryProperties) {
        try {
            Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
            Properties properties = System.getProperties();
            String s = properties.get("java.io.tmpdir").toString();
            String file = s.replaceAll("AppData\\\\Local\\\\Temp\\\\", "") + ".gitconfig";
            Optional<String> any = FileUtil.readUtf8Lines(file).stream().filter(e -> e.contains("=")).findAny();
            if (any.isPresent()) {
                String[] split = any.get().trim().split("=");
                metadata.put(split[0], split[1]);
            }
        } catch (Exception ignored) {

        }
        return null;
    }

}
